package org.mp3weezel.strands.services;

import java.util.HashMap;
import java.util.Map;

import org.mp3weezel.strands.StrandsAPI;
import org.mp3weezel.strands.StrandsServiceException;
import org.mp3weezel.strands.domain.SimpleAlbumList;
import org.mp3weezel.strands.domain.SimpleArtistList;
import org.mp3weezel.strands.domain.SimpleTrackList;

/**
 * Resolution services enable you to find the best matching items in the
 * MyStrands catalog for given strings. Fuzzy matching is performed to resolve
 * any given names to the best matching items.
 * 
 * @author Christian Humer
 */
public class ResolutionService extends AbstractService {

	public ResolutionService(StrandsAPI api) {
		super(api);
	}

	/**
	 * Returns the best matching artists for the given names; or an empty
	 * element with ArtistId=-1 if resolution fails.
	 * 
	 * @param names
	 * @return
	 * @throws StrandsServiceException
	 */
	public SimpleArtistList matchArtists(String[] names)
			throws StrandsServiceException {
		Map<String, String[]> parameter = new HashMap<String, String[]>();
		parameter.put("name", names);
		return (SimpleArtistList) request("/match/artists", parameter);
	}

	/**
	 * Returns the best matching albums for the given names; or and empty
	 * element with AlbumId=-1 if resolution fails.
	 * 
	 * @param names
	 *            are a pipe-delimited triple of strings: artist| album|track
	 * @return
	 * @throws StrandsServiceException
	 */
	public SimpleAlbumList matchAlbums(String[] names)
			throws StrandsServiceException {
		Map<String, String[]> parameter = new HashMap<String, String[]>();
		parameter.put("name", names);
		return (SimpleAlbumList) request("/match/albums", parameter);
	}

	/**
	 * Returns the best matching tracks for the given names; or an empty element
	 * with TrackId=-1 if resolution fails.
	 * 
	 * @param names
	 *            are a pipe-delimited triple of strings: artist| album|track
	 * @return
	 * @throws StrandsServiceException
	 */
	public SimpleTrackList matchTracks(String[] names)
			throws StrandsServiceException {
		Map<String, String[]> parameter = new HashMap<String, String[]>();
		parameter.put("name", names);
		return (SimpleTrackList) request("/match/tracks", parameter);
	}

}
